package net.coding.api.test;

import redis.clients.jedis.Jedis;

import java.util.Set;

/**
 * Created by zhengkenghong on 8/24/16.
 */
public class JedisClient {
    public static final TestConfig CONFIG = TestConfig.getInstance();
    private static Jedis jedis = new Jedis(CONFIG.getProperty("redis.host"),
            Integer.parseInt(CONFIG.getProperty("redis.port")));

    public static String getValue(String key) {
        return jedis.get(key);
    }

    public static Set<String> findKeysMatchingPattern(String pattern) {
        return jedis.keys(pattern);
    }

    public static String setValue(String key, String value) {
        return jedis.set(key, value);
    }

    /**
     * 获取手机注册码
     * redis-key: UserService.checkValidationCode
     *
     * @param phone
     * @return
     */
    public static String getRegisterPhoneCode(String phone) {
        String key = "register:phone:" + phone + ":+86:code";
        return getValue(key);
    }
}
